package com.usian.goods.service.impl;


import com.usian.goods.entity.ResultResponse;
import com.usian.goods.mapper.GoodsMapper;
import com.usian.goods.mapper.TypeMapper;
import com.usian.goods.service.GoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.goods.service.ITypeService;
import com.usian.goods.vo.GoodsVo;
import com.usian.model.goods.Goods;
import com.usian.model.goods.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

import java.util.List;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author wyp
 * @since 2024-12-17
 */
@Service
@Transactional
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public void shangGoods(Integer id) {
        goodsMapper.shangGoods(id);
    }

    public GoodsServiceImpl(GoodsMapper goodsMapper) {
        this.goodsMapper = goodsMapper;
    }

    @Override
    public GoodsVo findScoreId(GoodsVo goodsVo) {
        String id = goodsVo.getId();
        Integer numbers = goodsVo.getNumbers();
        int result = goodsMapper.findScoreId(id, numbers);// 调用mapper方法
        System.out.println("result=" + result);
        return goodsVo;// 返回结果
    }

    @Override
    public void xiaGoods(Integer id) {
        goodsMapper.xiaGoods(id);
    }

    @Override
    public ResultResponse findGoodsByType(Integer tid) {
        // 调用 Mapper 方法并返回结果
        List<Goods> goodsList = goodsMapper.findGoodsByType(tid);
        System.out.println("goodsList=" + goodsList);
        return ResultResponse.ok().data("goodsList", goodsList);
    }

    @Override
    public List<Goods> findGoods() {
        return goodsMapper.findGoods();
    }



}
